<template>
  <div class="site-wraps">
    <div class="site-swiper">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in bannerArr" :key="index">
          <img :src="item" alt="" />
        </van-swipe-item>
      </van-swipe>
    </div>

    <!-- 场馆介绍 -->
    <div class="site-info">
      <div class="info-top">
        <div class="site-title">{{ siteInfo.site_name }}</div>
        <div class="site-toggle">
          <img class="toggle-btn" src="./../../assets/img/toggle.png" />
          <div class="txt">切换场馆</div>
        </div>
      </div>
      <div class="info-bottom">
        <div class="address">{{ siteInfo.city }}市{{ siteInfo.address }}</div>
        <div class="right">
          <img
            class="nav"
            @click="goToLocation"
            src="./../../assets/img/nav.png"
          />
          <div class="line"></div>
          <img
            class="phone"
            @click="callPhoneNumber()"
            src="./../../assets/img/phone.png"
          />
        </div>
      </div>
    </div>

    <div class="tag-wrap">
      <div class="times-box">
        <div
          :class="['status', siteInfo.status == 'OPEN' ? 'status-green' : '']"
        >
          {{ siteInfo.status == 'OPEN' ? '开放中' : '关闭中' }}
        </div>
        <div class="times">{{ siteInfo.open_time }}</div>
      </div>
      <div class="card-wrap">
        <div class="capacity">{{ siteInfo.capacity }}人</div>
        <!-- <div class="card-box" v-for="item in siteInfo.key_words"> -->
        <div class="card-box">
          <div class="every">室内游泳</div>
          <div class="every">深水区</div>
          <div class="every">浅水区</div>
          <div class="every">儿童游泳</div>
          <div class="every">游泳培训</div>
          <div class="every">每日消毒</div>
        </div>
      </div>
    </div>

    <!-- 泳票列表 -->
    <div class="content">
      <div class="content-inner">
        <div
          class="inner-item"
          v-for="(item, index) in titckTemplates"
          :key="index"
        >
          <div class="item-left">
            <img :src="item.image_url" />
          </div>
          <div class="item-content">
            <div class="item-title">{{ item.template_title }}</div>
            <div class="center-box">
              <div class="ticket_times">
                {{ item.ticket_times == 1 ? '单次卡' : '多次卡' }}
              </div>
              <div class="line">|</div>
              <div class="one_day">
                {{ item.one_day == 1 ? '指定日期' : '不指定日期' }}
              </div>
            </div>
            <div class="price-wrap" @click="handleBuy(item.template_id)">
              <div class="item-price-box">
                <text class="item-unit">￥</text>
                <text class="item-price">{{ item.ticket_price / 100 }}</text>
                <text class="item-qi">起</text>
              </div>
              <div class="pay-wrap">
                <div
                  :class="[
                    'pay-btn',
                    item.charge_platform == 'YAN30' ? '' : 'free-btn',
                  ]"
                >
                  {{ item.charge_platform == 'YAN30' ? '抢购' : '领取' }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
// import wx from 'weixin-js-sdk';
import { onMounted, reactive, toRefs, ref, watch } from 'vue'
import { postData } from '@/request/request.js'
import { useRoute, useRouter } from 'vue-router'
let router = useRouter()
let route = useRoute()
let query = route.query
localStorage.clear()
localStorage.setItem('user_id', query.user_id)
localStorage.setItem('access_token', query.access_token)
localStorage.setItem('open_id', query.open_id)
localStorage.setItem('currentPath', query.currentPath)

let site_code = ref('')
let bannerArr = ref([])
let siteInfo = ref('')
let titckTemplates = ref([])

let initSiteInfo = () => {
  postData('/common/site/info', { site_code: '17001', with_images: 1 })
    .then((res) => {
      siteInfo.value = res.datas
      let bannerPic = res.datas.images
      bannerArr.value.push(
        bannerPic.logo1,
        bannerPic.logo2,
        bannerPic.logo3,
        bannerPic.logo4,
        bannerPic.logo5,
        bannerPic.logo6,
        bannerPic.logo7,
        bannerPic.logo8,
        bannerPic.logo9
      )
      site_code.value = res.datas.images.site_code
      initTemplateList(site_code.value)
    })
    .catch((err) => {
      console.log(err)
    })
}

let initTemplateList = (site_code) => {
  postData('/common/ticket/template/list', {
    user_id: localStorage.getItem('user_id'),
    site_code: site_code,
  })
    .then((res) => {
      titckTemplates.value = res?.datas?.templates
    })
    .catch((err) => {
      console.log(err)
    })
}

let handleBuy = (id) => {
  // router.push('/titckDetail')
  wx &
    wx.miniProgram.navigateTo({
      url: `/pagesB/siteTitckDetail/index?id=${id}`,
    })
}

let goToLocation = () => {
  wx &&
    wx.miniProgram.navigateTo({
      url: '/pagesB/location',
    })
}

let callPhoneNumber = () => {
  wx &&
    wx.miniProgram.navigateTo({
      url: '/pagesB/callPhone',
    })
}

onMounted(() => {
  // let user_id = localStorage.getItem('user_id')
  // let currentPath = localStorage.getItem('currentPath')
  // if (!user_id || user_id == '') {
  //   wx &&
  //     wx.miniProgram.redirectTo({
  //       url:
  //         '/pages/loginPhone/loginPhone?currentPath=' +
  //         encodeURIComponent(currentPath),
  //     })
  // } else {
  //   initSiteInfo()
  // }
  initSiteInfo()
})

watch(
  () => route.fullPath,
  () => {
    // let user_id = localStorage.getItem('user_id')
    //let currentPath = localStorage.getItem('currentPath')
    // if (!user_id || user_id == '') {
    // wx &&
    //   wx.miniProgram.redirectTo({
    //     url:
    //       '/pages/loginPhone/loginPhone?currentPath=' +
    //       encodeURIComponent(currentPath),
    //   })
    // } else {
    //   initSiteInfo()
    // }
    initSiteInfo()
  }
)
</script>

<style scoped>
.site-wraps {
  width: 100%;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
  padding-top: 0;
  margin-top: 0;
  font-size: 0.16rem;
  color: #333;
  background: #f7f7f8;
}

.site-swiper {
  height: 2rem;
  padding-top: 0;
  margin-top: 0;
}
.my-swipe {
  width: 100%;
  height: 100%;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 0.12rem;
  line-height: 2rem;
  text-align: center;
  background-color: #39a9ed;
}
.van-swipe-item img {
  width: 100%;
  height: 100%;
}

/* info */
.site-info {
  width: 94%;
  height: 1rem;
  border-radius: 0.1rem;
  background: #fff;
  margin: 0 auto;
  margin-top: -0.15rem;
  z-index: 999;
  position: relative;
  opacity: 1;
  box-shadow: 0.02rem 0.02rem 0.08rem rgba(0, 0, 0, 0.15);
  padding: 0 0.2rem;
  box-sizing: border-box;
}

.site-info .info-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 0.01rem dashed #e4e1e1;
  height: 0.5rem;
  line-height: 1;
}
.site-title {
  font-size: 0.16rem;
}

.site-toggle {
  padding: 0.1rem;
  border-radius: 0.15rem 0 0 0.15rem;
  position: absolute;
  right: 0;
  width: auto;
  height: 0.4rem;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 0.12rem;
  color: #6e6d6d;
}

.site-toggle .toggle-btn {
  width: 0.18rem;
  height: 0.18rem;
  margin-right: 0.1rem;
}

.site-info .info-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 0.5rem;
  line-height: 1;
}

.info-bottom .address {
  font-size: 0.14rem;
}

.info-bottom .right {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.info-bottom .right .nav {
  width: 0.2rem;
  height: 0.2rem;
}
.info-bottom .right .line {
  width: 0.01rem;
  height: 0.16rem;
  color: #f6c782;
  margin: 0 0.1rem;
  background: #f6c782;
}
.info-bottom .right .phone {
  width: 0.2rem;
  height: 0.2rem;
}

/*  */
.tag-wrap {
  box-sizing: border-box;
  padding: 0 0.1rem;
  padding: 0.25rem 0.1rem;
  background: #fff;
}

.times-box {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 0.14rem;
}

.times-box .status {
  color: #988b4b;
  margin-right: 0.1rem;
}

.times-box .status-green {
  color: #4cd964;
}

.card-wrap {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 0.12rem;
  margin-top: 0.15rem;
}

.card-box {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  overflow-x: hidden;
}

.every,
.capacity {
  margin-right: 0.01rem;
  padding: 0.02rem 0.03rem;
  border-radius: 0.1rem;
  color: #6d6a6a;
  background: #eeefee;
  white-space: nowrap;
}

.capacity {
  color: #ff9800;
}

/*  */
.content {
  width: 100%;
  height: auto;
  box-sizing: border-box;
  padding: 0 0.1rem;
  background: #fff;
  padding-bottom: 0.8rem;
}

.content-title {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  box-sizing: border-box;
  padding: 0.1rem 0;
}

.content-line {
  width: 0.03rem;
  height: 0.2rem;
  background-color: #d5ad57;
  border-radius: 0.01rem;
  box-sizing: border-box;
}

.index-title {
  color: #151817;
  font-size: 0.16rem;
  margin-left: 0.15rem;
  box-sizing: border-box;
}

.index-title-icon-wrap {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.24rem;
  box-sizing: border-box;
  background: #fff;
  padding: 0.1rem;
}

.index-title-icon-item {
  width: 0.47rem;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  box-sizing: border-box;
}

.index-title-icon {
  width: 0.47rem;
  height: 0.47rem;
  background-color: #fdfbeb;
  border-radius: 50%;
  font-size: 0.14rem;
  color: #d5ad57;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.index-title-icon-item-active .index-title-icon {
  background-color: #d5ad57;
  color: #fff;
  box-sizing: border-box;
}

.index-title-icons {
  width: 0.32rem;
  height: 0.32rem;
}

.index-title-icon-txt {
  margin-top: 0.12rem;
  color: #010101;
  font-size: 0.14rem;
  box-sizing: border-box;
}

.content-inner {
  width: 100%;
  height: auto;
  overflow: hidden;
  box-sizing: border-box;
}

.inner-item {
  width: 100%;
  height: auto;
  /* padding: 0 0.1rem; */
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.1rem;
  background: #f3f5f36e;
}

.item-left {
  width: 0.74rem;
  height: auto;
}

.item-left img {
  width: 0.74rem;
  height: 0.74rem;
  box-sizing: border-box;
  object-fit: contain;
  border-radius: 0.06rem;
}

.item-content {
  flex: 1;
  margin-left: 0.2rem;
  padding: 0.1rem;
}

.center-box {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-top: 0.08rem;
  color: #1a1b1d;
}

.center-box .ticket_times,
.one_day {
  box-sizing: border-box;
  font-size: 0.14rem;
}

.center-box .line {
  margin: 0 0.1rem;
  width: 0.01rem;
  height: auto;
  color: #969698;
}

.item-title {
  color: #151817;
  box-sizing: border-box;
}

.item-date {
  color: #1a1b1d;
  margin-top: 0.04rem;
  box-sizing: border-box;
  font-size: 0.14rem;
}

.item-time {
  color: #1a1b1d;
  margin-top: 0.04rem;
  box-sizing: border-box;
  font-size: 0.14rem;
}

.price-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.08rem;
}

.item-price-box {
  margin-top: 0.04rem;
  box-sizing: border-box;
  color: #dd524d;
}

.item-unit {
  font-size: 0.12rem;
}

.item-price {
  margin-left: 0.03rem;
  font-size: 0.16rem;
}

.item-qi {
  margin-left: 0.1rem;
  font-size: 0.14rem;
}

.pay-wrap {
  width: 0.7rem;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.pay-btn {
  width: auto;
  height: auto;
  padding: 0.05rem 0.2rem;
  border-radius: 0.08rem;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(to right, #e3a173, #e1925d, #e26f21);
  color: #fff;
  box-sizing: border-box;
  font-size: 0.14rem;
}

.free-btn {
  /* background: #d5ad57; */
  color: #725722;
  background: linear-gradient(to right, #feefc6, #f5d67b, #eab92e);
}

.index-venue-item {
  align-items: flex-start;
}

.index-grid-wrap {
  width: 100%;
  height: auto;
  display: grid;
  gap: 0.1rem;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto;
  margin-top: 0.1rem;
}

.index-content-item {
  width: 1fr;
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
}

.index-content-item img {
  width: 1rem;
  height: 1rem;
  border-radius: 0.1rem;
}

.index-grid-title {
  color: #010101;
  margin-top: 0.05rem;
  font-weight: 500;
}

.index-venue-item .item-left img {
  width: 100%;
}
</style>
